package com.allenlee.mvphelper.module.testinfo;

import android.annotation.SuppressLint;
import android.view.View;

import com.allenlee.mvphelper.R;
import com.allenlee.mvphelper.base.BaseFragment;
import com.qmuiteam.qmui.arch.SwipeBackLayout;
import com.qmuiteam.qmui.util.QMUIViewHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;

/**
 * @author : lifei
 * 创建时间： 19-12-17
 * 更改时间： 19-12-17
 * Email : allen.lee723@qq.com
 * @version :
 * Description： 错误信息界面
 */
public class TestInfoFragment extends BaseFragment<TestInfoPresenter> implements TestInfoContract.View {

    @BindView(R.id.topbar)
    QMUITopBarLayout mTopbar;
    @BindView(R.id.fragment_test_info_recyclerView)
    RecyclerView mRecyclerView;

    private List<TestInfo> mData;
    private TestInfoAdapter mAdapter;

    @Override
    protected void beforeInitView() {

    }

    @Override
    protected int getLayout() {
        return R.layout.fragment_test_info;
    }

    @Override
    protected void initTopbar() {
        mTopbar.setTitle("错误信息");
        mTopbar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                popBackStack();
            }
        });
        mTopbar.addRightTextButton("反馈", QMUIViewHelper.generateViewId()).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showToast("反馈错误到后台");

            }
        });
    }

    @Override
    protected void initView() {
        //创建布局管理
        LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.addItemDecoration(new DividerItemDecoration(mActivity, DividerItemDecoration.VERTICAL));
        mRecyclerView.setLayoutManager(layoutManager);

        mData = new ArrayList<>();
        for (int i = 0; i < 20; i++) {
            @SuppressLint("SimpleDateFormat") SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd");
            @SuppressLint("SimpleDateFormat") SimpleDateFormat timeFormat = new SimpleDateFormat("HH:mm:ss");
            Date curDate = new Date(System.currentTimeMillis());
            TestInfo bean = new TestInfo();
            bean.setData(dateFormat.format(curDate));
            bean.setTime(timeFormat.format(curDate));
            bean.setSn((i + 1) + " - 12345678");
            bean.setDescribe("授权时间过期");
            mData.add(bean);
        }
        mAdapter = new TestInfoAdapter(mData);
        mRecyclerView.setAdapter(mAdapter);
    }

    @Override
    protected TestInfoPresenter setPresenter() {
        return new TestInfoPresenter();
    }

    @Override
    protected void afterSetPresenter() {

    }

    @Override
    public void success() {

    }

    @Override
    protected SwipeBackLayout.ViewMoveAction dragViewMoveAction() {
        return SwipeBackLayout.MOVE_VIEW_TOP_TO_BOTTOM;
    }
}